package com.loveyukari.controller;

import java.util.List;

import com.loveyukari.utils.AliYunUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loveyukari.model.XmMessage;
import com.loveyukari.service.XiaomaService;
import com.loveyukari.support.JsonResult;

/**
*
*yangshaohua
*2017年2月1日下午4:16:01
**/
@RequestMapping("/admin/xiaoma")
@Controller
public class XiaomaController {
	@Autowired
	private XiaomaService xiaomaService;
	
	@RequestMapping("/index")
	public String index(){
		return "xiaoma/index";
	}
	
	@RequestMapping("/me")
	public String me(){
		return "xiaoma/me";
	}
	
	@RequestMapping("/getMessage")
	@ResponseBody
	public JsonResult<Object> getMessage(Integer size){
		List<XmMessage> list = xiaomaService.getMessage(size);
		return new JsonResult<Object>(0,"",list);
	}

	@RequestMapping("/callXiaoma")
	@ResponseBody
	public JsonResult<String> callXiaoma(){
		AliYunUtils.callStartLive("18868877652",null);
		return new JsonResult<String>(0,"success","呼叫成功，请稍后");
	}
	
	@RequestMapping("/sendMessage")
	@ResponseBody
	public JsonResult<String> sendMessage(String msg,String name){
		if (StringUtils.isNotBlank(msg)){
			xiaomaService.addMessage(msg, name);
		}
		return new JsonResult<String>(0,"success","发送成功");
	}
	
}
